<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学员管理</title>
</head>
<body>
<body>
<div class="datagrid-header" id="student-grid_toolbar" style="width: 100%;">
		<table class="datagrid-htable" border="0" cellspacing="0"
			cellpadding="0" style="width: 100%;">
			 <tr class="datagrid-header-row" style="height: 30px;">
            <td align="left" style="border-style: solid; padding-left: 48px;">
                姓名： 
                <input style="width: 170px;" id="name"> 
            </td> 
             
            <td align="left" style="border-style: solid;"> 
                身份证号： 
                <input type="text" id="idNumber" name="idNumber" style="width: 170px"> 
            </td> 
            </tr> 
            </table>
    <table class="datagrid-htable" border="0" cellspacing="0" cellpadding="0" style="width:100%;">
        <tr class="datagrid-header-row" style="height: 40px;">
            <td colspan="6" align="left" style="border-style: solid;">
                <a href="javascript:void(0)" id="student-grid-add" class="easyui-linkbutton" data-options="iconCls:'icon-add'">增加</a>
                <a href="javascript:void(0)" id="student-grid-delete" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
                <a href="javascript:void(0)" id="student-grid-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>
                <a href="javascript:void(0)" id="student-grid-search" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
                <a href="javascript:void(0)" id="student-grid-Excel" class="easyui-linkbutton" data-options="iconCls:'icon-excel'">导出Excel</a>
            </td>
        </tr>
    </table>
</div>

<table id="student-grid"></table>

<div id="student-menu" class="easyui-menu" style="width:160px;">
    <div id="student-menu-view" data-options="iconCls:'icon-search'">查看</div>
    <div id="student-menu-delete" data-options="iconCls:'icon-remove'">删除</div>
    <div id="student-menu-edit" data-options="iconCls:'icon-edit'">编辑</div>
</div>

<script type="text/javascript">
    function func(){
        var vs = $('select  option:selected').val();
        alert(vs);
    }
    $(function(){
        $("#student-grid").datagrid({
        	title:"学员管理",
            toolbar:"#student-grid_toolbar",
            border:false,
            fit:true,
            width:$(window).width()-342,
            columns:[[
                {field:"ckb",checkbox:true},
                {field:"id",title:"id",width:20,halign:"center",align:"center",resizable:true,sortable:true},
                {field:"name",title:"名字",width:40,halign:"center",align:"center",resizable:true},
                {field:"idNumber",title:"身份证号",width:70,align:"center",resizable:true},
                {field:"sex",title:"性别",width:20,align:"center",resizable:true},
                {field:"age",title:"年龄",width:20,align:"center",resizable:true},
                {field:"phone",title:"手机",width:60,align:"center",resizable:true},
                {field:"candiCar",title:"报考车型",width:30,align:"center",resizable:true},
                {field:"applyTime",title:"报名时间",width:60,align:"center",resizable:true,formatter:function(value,row,index){
                	if (row.applyTime){
    					//格式化时间,formatDateTime在 DataUtil.js文件中
    					return formatDateTime(row.applyTime);
    				} else {
    					return row.applyTime;
    				}	
                }
            }
//                 ,
//                 {field:"updateTime",title:"修改时间",width:80,align:"center",resizable:false,formatter:function(value,row,index){
//                 	if (row.createTime){
//     					//格式化时间,formatDateTime在 DataUtil.js文件中
//     					return formatDateTime(row.createTime);
//     				} else {
//     					return row.createTime;
//     				}	
//                 }
//                 	}
            ]],
            //striped:true,
            fitColumns:true,
            //autoRowHeight:true,
            rownumbers:false,
            singleSelect:false,
            ctrlSelect:true,
            pagination:true,
            pageSize:10,
            pageList:[5,10,15,20,25,30],
            sortName:"corpId",
            sortOrder:"desc",
            url:"StudentServlet.do?method=query",
            method:"get",
            loadMsg:"加载数据中，请稍后",
            onDblClickRow:function(rowIndex, rowData){
                var selTr = $("#student-grid").datagrid("getSelections");
                openDialog({
                    type:"view",
                    title:"学员查看",
                    width:700,
                    height:250,
                    maximizable:true,
                    queryParams: { id: selTr[0].id},//设置了一个属性queryParams
                    href:"html/student/studentDetails.html"
                });
            },
            onRowContextMenu:function(e, rowIndex, rowData){
                e.preventDefault();

                $(this).datagrid("unselectAll");

                $(this).datagrid("selectRow", rowIndex);

                $("#student-menu").menu("show",{
                    left:event.pageX,
                    top:event.pageY
                });
            }
        }).datagrid("columnMoving")
                .datagrid("columnHiding");


        //相关功能按钮事件
        $("#student-grid-search").click(function(){
            $("#student-grid").datagrid("load",{
            	name:$("#name").val(),
            	idNumber:$("#idNumber").val()
            });
        });

        $("#student-grid-add").click(function(){
            openDialog({
                title:"学员添加",
                width:700,
                height:320,
                maximizable:false,
                href:"html/student/studentAdd.html"
            });
        });

        $("#student-grid-delete").click(function(){
            var selTr = $("#student-grid").datagrid("getSelections");

            if(selTr.length == 0){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:"请至少选择1条记录"
                });
            }else{
                var strIds = "";
                //拼接字符串，这里也可以使用数组，作用一样
                //1234  1,2,3,4  String[]{"1","2","3","4"}
                for (var i = 0; i < selTr.length; i++) {
                    strIds += selTr[i].id + ",";
                }
                $.ajax({
                    url :'StudentServlet.do?method=delete&ids='+strIds,
                    dataType : 'json',
                    type : 'delete',
                    success : function(data) {
                     	if(data.resultCode=="1"){
	                        Messager.show({
	                            title:"&nbsp;",
	                            content:"删除成功"
	                        });
	                        $("#student-grid-search").click();
                    	}else{
                    		 Messager.show({
 	                            title:"&nbsp;",
 	                            content:data.resultMessage
 	                        });
                    	}
                    },
                    //400 500,505异常进入,不是json类型的数据
                    error : function(data) {
                        Messager.show({
                            title:"&nbsp;",
                            content:"删除失败"
                        });
                    }
                });
            }
        });

        $("#student-grid-edit").click(function(){
            var selTr = $("#student-grid").datagrid("getSelections");

            var infoMsg = null;

            infoMsg = selTr.length < 1 ? "请选择一条记录" : (selTr.length > 1 ? "最多只能选择一条记录" : null);

            if(null != infoMsg){
                Messager.alert({
                    type:"info",
                    title:"&nbsp;",
                    content:infoMsg
                });
            }else{
                openDialog({
                    title:"学员编辑",
                    width:600,
                    height:320,
                    maximizable:false,
                    queryParams: { id: selTr[0].id},//设置了一个属性queryParams
                    href:"html/student/studentEdit.html"
                });
            }
        });
        //导出Excel
        $("#student-grid-Excel").click(function(){
			location.href='StudentServlet.do?method=export';
        });

        //查看
        $("#student-menu-view").click(function(){
            new($("#student-grid").datagrid("options").onDblClickRow);
        });
      	//删除
        $("#student-menu-delete").click(function(){
            $("#student-grid-delete").click();
        });
      	//编辑
        $("#student-menu-edit").click(function(){
            $("#student-grid-edit").click();
        });

    });
</script>
</body>
</html>